SonarSource Rules
  • Products

    In-IDE

    Code Quality and Security in your IDE with SonarQube Ide

    IDE extension that lets you fix coding issues before they exist!

    Discover SonarQube for IDE

    SaaS

    Code Quality and Security in the cloud with SonarQube Cloud

    Setup is effortless and analysis is automatic for most languages

    Discover SonarQube Cloud

    Self-Hosted

    Code Quality and Security Self-Hosted with SonarQube Server

    Fast, accurate analysis; enterprise scalability

    Discover SonarQube Server
  • SecretsSecrets
  • ABAPABAP
  • AnsibleAnsible
  • ApexApex
  • AzureResourceManagerAzureResourceManager
  • CC
  • C#C#
  • C++C++
  • CloudFormationCloudFormation
  • COBOLCOBOL
  • CSSCSS
  • DartDart
  • DockerDocker
  • FlexFlex
  • GitHub ActionsGitHub Actions
  • GoGo
  • GroovyGroovy
  • HTMLHTML
  • JavaJava
  • JavaScriptJavaScript
  • JSONJSON
  • JCLJCL
  • KotlinKotlin
  • KubernetesKubernetes
  • Objective CObjective C
  • PHPPHP
  • PL/IPL/I
  • PL/SQLPL/SQL
  • PythonPython
  • RPGRPG
  • RubyRuby
  • RustRust
  • ScalaScala
  • ShellShell
  • SwiftSwift
  • TerraformTerraform
  • TextText
  • TypeScriptTypeScript
  • T-SQLT-SQL
  • VB.NETVB.NET
  • VB6VB6
  • XMLXML
  • YAMLYAML
Groovy

Groovy static code analysis

Unique rules to find Bugs, Vulnerabilities, Security Hotspots, and Code Smells in your GROOVY code

  • All rules 21
  • Bug5
  • Code Smell16
 
Tags
    Impact
      Clean code attribute
        1. Range methods should be used appropriately to avoid unexpected behavior

           Code Smell
        2. Property names should use camelCase

           Code Smell
        3. Simple "@Grab" annotations should use shorthand notation

           Code Smell
        4. Empty strings should not be used for type conversion

           Code Smell
        5. Static imports should appear before regular imports

           Code Smell
        6. Method names should not use reserved keywords

           Code Smell
        7. Do not use "sort(false)" to avoid confusion

           Code Smell
        8. Semicolons should be omitted in Groovy

           Code Smell
        9. Control structures should use braces

           Code Smell
        10. Duplicate import statements should be removed

           Code Smell
        11. Star imports should be replaced with explicit imports

           Code Smell
        12. AST transformation classes should be annotated with "@CompileStatic"

           Code Smell
        13. File operations should specify charset encoding

           Code Smell
        14. Test methods should contain assertions

           Code Smell
        15. Method names should follow camelCase naming conventions

           Code Smell
        16. Groovy parser failure

           Code Smell

        Do not use "sort(false)" to avoid confusion

        intentionality - clear
        maintainability
        Code Smell

          This rule raises an issue when code uses sort(false) instead of toSorted(), or when the result of a mutating sort() call is assigned to a variable.

          Why is this an issue?

          How can I fix it?

          More Info

          Groovy collections can be sorted either by mutating the original collection or by creating a new one. The sort() method sorts the collection in place and returns the same instance. When you assign this result to another variable, it is easy to assume you now have two independent collections, while in reality both variables point to the same, already modified collection.

          Using sort(false) to get a new sorted collection is also confusing. The meaning of the false argument is not obvious, so readers must remember a Groovy special case instead of understanding the code directly. The toSorted() method was introduced to make this intent explicit: it returns a new sorted collection and keeps the original unchanged.

          What is the potential impact?

          Misusing these sorting methods can hide mutations, which makes defects harder to reproduce, increases maintenance cost, and can compromise reliability when collections are shared between components or threads.

            Available In:
          • SonarQube CloudDetect issues in your GitHub, Azure DevOps Services, Bitbucket Cloud, GitLab repositories

          © 2026 SonarSource Sàrl. All rights reserved.

          Privacy Policy | Cookie Policy | Terms of Use